//
//  CZCommentCellHeaderView.swift
//  GZWeibo007
//
//  Created by Raymond on 15/12/24.
//  Copyright © 2015年 Apple. All rights reserved.
//

import UIKit

protocol CZCommentCellHeaderViewDelegate: NSObjectProtocol {
    func commentCellHeaderViewCommentButtonDidClick()
}
/// 评论头部View
class CZCommentCellHeaderView: UIView {

    // MARK: - 属性
    /// 模型
    var commentCount: Int?{
        didSet{
            setCount()
        }
    }
    
    /// 代理
    weak var delegate: CZCommentCellHeaderViewDelegate?
    
    // MARK: - 方法
    private func setCount(){
        commentButton.setTitle("评论\(commentCount ?? 0)", forState: UIControlState.Normal)
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor.whiteColor()
        prepareUI()
        
    }
    private func prepareUI() {
        addSubview(separatorView)
        addSubview(commentButton)
        
        separatorView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: UIScreen.mainScreen().bounds.width, height: 10))
        
        commentButton.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: separatorView, size: nil, offset: CGPoint(x: 25, y: 10))
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    // 按钮监听方法
    func commentButtonDidClick() {
        delegate?.commentCellHeaderViewCommentButtonDidClick()
    }
    
    // MARK: - 懒加载
    private lazy var commentButton:UIButton = {
        let button = UIButton()
        // 获取评论数
        button.backgroundColor = UIColor.clearColor()
        
        button.setTitleColor(UIColor.lightGrayColor(), forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(12)
        // 添加事件
        button.addTarget(self, action: "commentButtonDidClick", forControlEvents: UIControlEvents.TouchUpInside)
        return button
    }()
    // 分割视图
    private lazy var separatorView: UIView = {
        let view = UIView()
        
        // 设置背景
        view.backgroundColor = UIColor(white: 0.95, alpha: 1)
        
        return view
    }()

}
